package xalan.smartgwt.criteria;

/**
 * Wszystkie typy operatorów występujące w kryterium wyszukiwania.
 * 
 * Klasa utworzona na podstawie klasy OperatorId z biliboteki SmartGWT.
 * 
 * @author Xalan
 */
public enum Operator {
	/**
     * exactly equal to
     */
    EQUALS("equals", "=", false, false, false, false),
    
    /**
     * not equal to
     */
    NOT_EQUAL("notEqual", "<>", false, false, true, false),
    /**
     * exactly equal to, if case is disregarded
     */
    IEQUALS("iEquals", "=", false, false, false, true),
    /**
     * not equal to, if case is disregarded
     */
    INOT_EQUAL("iNotEqual", "<>", false, false, true, true),
    /**
     * Greater than
     */
    GREATER_THAN("greaterThan", ">", false, false, false, false),
    /**
     * Less than
     */
    LESS_THAN("lessThan", "<", false, false, false, false),
    /**
     * Greater than or equal to
     */
    GREATER_OR_EQUAL("greaterOrEqual", ">=", false, false, false, false),
    /**
     * Less than or equal to
     */
    LESS_OR_EQUAL("lessOrEqual", "<=", false, false, false, false),
    /**
     * Contains as sub-string (match case)
     */
    CONTAINS("contains", "LIKE", true, true, false, false),
    /**
     * Starts with (match case)
     */
    STARTS_WITH("startsWith", "LIKE", false, true, false, false),
    /**
     * Ends with (match case)
     */
    ENDS_WITH("endsWith", "LIKE", true, false, false, false),
    /**
     * Contains as sub-string (case insensitive)
     */
    ICONTAINS("iContains", "LIKE", true, true, false, true),
    
    /**
     * Starts with (case insensitive)
     */
    ISTARTS_WITH("iStartsWith", "LIKE", false, true, false, true),
    /**
     * Ends with (case insensitive)
     */
    IENDS_WITH("iEndsWith", "LIKE", true, false, false, true),
    /**
     * Does not contain as sub-string (match case)
     */
    NOT_CONTAINS("notContains", "LIKE", true, true, true, false),
    /**
     * Does not start with (match case)
     */
    NOT_STARTS_WITH("notStartsWith", "LIKE", false, true, true, false),
    /**
     * Does not end with (match case)
     */
    NOT_ENDS_WITH("notEndsWith", "LIKE", true, false, true, false),
    /**
     * Does not contain as sub-string (case insensitive)
     */
    INOT_CONTAINS("iNotContains", "LIKE", true, true, true, true),
    /**
     * Does not start with (case insensitive)
     */
    INOT_STARTS_WITH("iNotStartsWith", "LIKE", false, true, true, true),
    /**
     * Does not end with (case insensitive)
     */
    INOT_ENDS_WITH("iNotEndsWith", "LIKE", true, false, true, true),
    /**
     * Regular expression match
     */
    REGEXP("regexp", "", false, false, false, false),
    /**
     * Regular expression match (case insensitive)
     */
    IREGEXP("iregexp", "", false, false, false, false),
    /**
     * value is null
     */
    IS_NULL("isNull", "IS NULL", false, false, false, false),
    /**
     * value is non-null.  Note empty string ("") is non-null
     */
    NOT_NULL("notNull", "IS NOT NULL", false, false, false, false),
    /**
     * value is in a set of values.  Specify criterion.value as an Array
     */
    IN_SET("inSet", "", false, false, false, false),
    /**
     * value is not in a set of values.  Specify criterion.value as an Array
     */
    NOT_IN_SET("notInSet", "", false, false, false, false),
    /**
     * matches another field (specify fieldName as criterion.value)
     */
    EQUALS_FIELD("equalsField", "=", false, false, false, false),
    /**
     * does not match another field (specify fieldName as criterion.value)
     */
    NOT_EQUAL_FIELD("notEqualField", "<>", false, false, false, false),
    /**
     * Greater than another field (specify fieldName as criterion.value)
     */
    GREATER_THAN_FIELD("greaterThanField", ">", false, false, false, false),
    /**
     * Less than another field (specify fieldName as criterion.value)
     */
    LESS_THAN_FIELD("lessThanField", "<", false, false, false, false),
    /**
     * Greater than or equal to another field (specify fieldName as criterion.value)
     */
    GREATER_OR_EQUAL_FIELD("greaterOrEqualField", ">=", false, false, false, false),
    /**
     * Less than or equal to another field (specify fieldName as criterion.value)
     */
    LESS_OR_EQUAL_FIELD("lessOrEqualField", "<=", false, false, false, false),
    /**
     * Contains as sub-string (match case) another field value (specify fieldName as
     * criterion.value)
     */
    CONTAINS_FIELD("containsField", "LIKE", true, true, false, false),
    /**
     * Starts with (match case) another field value (specify fieldName as criterion.value)
     */
    STARTS_WITH_FIELD("startsWithField", "LIKE", false, true, false, false),
    /**
     * Ends with (match case) another field value (specify fieldName as criterion.value)
     */
    ENDS_WITH_FIELD("endsWithField", "LIKE", true, false, false, false),
    /**
     * all subcriteria (criterion.criteria) are true
     */
    AND("and", "", false, false, false, false),
    /**
     * all subcriteria (criterion.criteria) are false
     */
    NOT("not", "", false, false, false, false),
    /**
     * at least one subcriteria (criterion.criteria) is true
     */
    OR("or", "", false, false, false, false),
    /**
     * shortcut for greaterThan + lessThan + and. Specify criterion.start and criterion.end
     */
    BETWEEN("between", "BETWEEN", false, false, false, false),
    /**
     * shortcut for greaterOrEqual + lessOrEqual + and. 
     * Specify criterion.start and criterion.end
     */
    BETWEEN_INCLUSIVE("betweenInclusive", "BETWEEN", false, false, false, false);
    
    private Operator(String value, String operator, boolean percentPrefix,
			boolean percentPostfix, boolean negation, boolean caseIntensitive) {
		this.value = value;
		this.operator = operator;
		this.percentPrefix = percentPrefix;
		this.percentPostfix = percentPostfix;
		this.negation = negation;
		this.caseIntensitive = caseIntensitive;
	}

	public String getValue() {
		return value;
	}
    
    public String getOperator() {
    	return operator;
    }
    
	public boolean isPercentPrefix() {
		return percentPrefix;
	}

	public boolean isPercentPostfix() {
		return percentPostfix;
	}

	public boolean isNegation() {
		return negation;
	}

	public boolean isCaseIntensitive() {
		return caseIntensitive;
	}

	private String value;
	private String operator;
	private boolean percentPrefix;
	private boolean percentPostfix;
	private boolean negation;
	private boolean caseIntensitive;
}
